package com.haitaoit.chengquan.module.center;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.ExitApplication;
import com.haitaoit.chengquan.base.MyCallBack;
import com.haitaoit.chengquan.bean.HaveNeerReedBeen;
import com.haitaoit.chengquan.bean.OrderNumObj;
import com.haitaoit.chengquan.module.center.activity.info.CenterInfoActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyCollectActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyCouponActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyEvaluateActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyForumActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyJobActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyMessageActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyMoneyActivity;
import com.haitaoit.chengquan.module.center.activity.info.MyPointActivity;
import com.haitaoit.chengquan.module.center.activity.info.QMyAddressActivity;
import com.haitaoit.chengquan.module.center.activity.order.MyOrderActivity;
import com.haitaoit.chengquan.module.center.activity.return_goods.MyReturnActivity;
import com.haitaoit.chengquan.module.center.activity.xuqiu.MyXuqiuActivity;
import com.haitaoit.chengquan.module.center.activity.yuyue.MyYuyueActivity;
import com.haitaoit.chengquan.module.center.model.UserInfoModel;
import com.haitaoit.chengquan.module.center_service.activity.ServiceEvaluateActivity;
import com.haitaoit.chengquan.module.center_service.activity.ServiceInfoActivity;
import com.haitaoit.chengquan.module.center_service.activity.ServiceRecruitActivity;
import com.haitaoit.chengquan.module.center_service.activity.service_order.ServiceFuwuActivity;
import com.haitaoit.chengquan.module.center_service.activity.xuqiu_order.ServiceXuqiuActivity;
import com.haitaoit.chengquan.module.login.LoginActivity;
import com.haitaoit.chengquan.ui.equipment.request.ApiRequest;
import com.haitaoit.chengquan.utils.Constant;
import com.haitaoit.chengquan.utils.GetSign;
import com.haitaoit.chengquan.utils.HttpUtilsSingle;
import com.haitaoit.chengquan.utils.NameValuePairSign;
import com.haitaoit.chengquan.utils.PreferenceUtils;
import com.haitaoit.chengquan.utils.ToastUtils;
import com.haitaoit.chengquan.view.CircleImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.squareup.leakcanary.RefWatcher;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

/**
 * Created by Administrator on 2016/9/22.
 */
public class CenterFragment extends Fragment {
    @ViewInject(R.id.center_name)
    TextView        center_name;
    @ViewInject(R.id.all_count)
    TextView        all_count;
    @ViewInject(R.id.center_img)
    CircleImageView center_img;
    @ViewInject(R.id.fl_xuqiushang)
    FrameLayout     fl_xuqiushang;
    @ViewInject(R.id.coupons_count)
    TextView        coupons_count;
    @ViewInject(R.id.integral)
    TextView        integral;
    @ViewInject(R.id.tv_usertype)
    TextView        tv_usertype;
    @ViewInject(R.id.ll_fuwushang)
    LinearLayout    ll_fuwushang;
    @ViewInject(R.id.service_balance)
    TextView        service_balance;
    @ViewInject(R.id.ll_menu_xuqiushang)
    LinearLayout    ll_menu_xuqiushang;
    //需求商显示的
    @ViewInject(R.id.need_all_count)
    TextView        need_all_count;
    @ViewInject(R.id.future_all_count)
    TextView        future_all_count;
    @ViewInject(R.id.ll_menu_fuwushang)
    LinearLayout    ll_menu_fuwushang;
    @ViewInject(R.id.service_xiuqiu_dd)
    LinearLayout    service_xiuqiu_dd;
    @ViewInject(R.id.service_chenge)
    LinearLayout    service_chenge;
    //服务商商显示的
    @ViewInject(R.id.servecr_all_count)
    TextView        servecr_all_count;
    @ViewInject(R.id.service_fuwu_dd)
    LinearLayout    service_fuwu_dd;
    @ViewInject(R.id.serverce_server_count)
    TextView        serverce_server_count;
    @ViewInject(R.id.service_eva)
    LinearLayout    service_eva;
    @ViewInject(R.id.service_zhaopin)
    LinearLayout    service_zhaopin;
    @ViewInject(R.id.service_money)
    LinearLayout    service_money;
    @ViewInject(R.id.center_group_gl_fuwu)
    LinearLayout    center_group_gl_fuwu;
    @ViewInject(R.id.ll_center_mall)
    LinearLayout    ll_center_mall;
    @ViewInject(R.id.tv_dfk)
    TextView        tv_dfk;
    @ViewInject(R.id.tv_dfh)
    TextView        tv_dfh;
    @ViewInject(R.id.tv_dsh)
    TextView        tv_dsh;
    @ViewInject(R.id.tv_dpj)
    TextView        tv_dpj;
    @ViewInject(R.id.tv_thh)
    TextView        tv_thh;
    @ViewInject(R.id.tv_version)
    TextView        tv_version;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tv_version.setText("版本号:" + getAppInfo());

        //需求商的
        need_all_count.setVisibility(View.GONE);
        future_all_count.setVisibility(View.GONE);

        //服务商的
        servecr_all_count.setVisibility(View.GONE);
        serverce_server_count.setVisibility(View.GONE);
        //        System.out.println(PreferenceUtils.getPrefString("user_id", "")+"wwwwwwwwwwwwwwwwwww");
        //        if (TextUtils.equals("", PreferenceUtils.getPrefString("user_id", ""))) {
        //            Intent intent = new Intent(getActivity(), LoginActivity.class);
        //            intent.putExtra("tag", "2");
        //            intent.putExtra("centerfragment", "100");
        //            startActivity(intent);
        //        } else {
        //            setViewForUser();
        //            getOrderNum(PreferenceUtils.getPrefString("user_id", ""));
        //            httpGetUserInfo(PreferenceUtils.getPrefString("user_id", ""));
        //            //获取现有的消息
        //            initMessage();
        //            //获取需求管理的小红点数目
        //            initNeed(PreferenceUtils.getPrefString("user_id", ""));
        //            //获取需求管理
        //            initNeedManage(PreferenceUtils.getPrefString("user_id", ""));
        //            //获取预约管理
        //            initNeedFuture(PreferenceUtils.getPrefString("user_id", ""));
        //        }
    }

    @Override
    public void onResume() {
        //        PhoneUtils.hiddenKeyBoard(getActivity());

        String user_id = PreferenceUtils.getPrefString("user_id", "");
        SystemClock.sleep(300);
        if (TextUtils.equals("", user_id)) {
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.putExtra("tag", "2");
            intent.putExtra("centerfragment", "100");
            startActivity(intent);

        } else {

            setViewForUser();
            getOrderNum(PreferenceUtils.getPrefString("user_id", ""));
            httpGetUserInfo(PreferenceUtils.getPrefString("user_id", ""));

            //获取现有的消息
            initNeed(PreferenceUtils.getPrefString("user_id", ""));
            //获取需求管理
            initNeedManage(PreferenceUtils.getPrefString("user_id", ""));
            //获取预约管理
            initNeedFuture(PreferenceUtils.getPrefString("user_id", ""));

        }
        super.onResume();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_center, null);
        ViewUtils.inject(this, v);
        return v;
    }

    private void initNeedFuture(final String userId) {
        Map<String, String> map = new HashMap<>();
        map.put("user_id", userId);
        final String sign = GetSign.getSign(map);
        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpUtils
                        .get()
                        .url(Constant.GETUER_SERVICE_COUNT)
                        .addParams("user_id", userId)
                        .addParams("sign", sign)
                        .build()
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Call call, Exception e, int id) {
                                ToastUtils.showToast("网络请求异常");
                            }

                            @Override
                            public void onResponse(String response, int id) {
                                Gson gson = new Gson();
                                final HaveNeerReedBeen been = gson.fromJson(response, HaveNeerReedBeen.class);
                                if (been == null) {
                                    ToastUtils.showToast("网络请求异常");
                                    return;
                                }
                                if (!TextUtils.equals("0", been.getErrCode())) {
                                    ToastUtils.showToast(been.getErrMsg());
                                    return;
                                }
                                if (TextUtils.equals("0", been.getErrCode())) {
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            if (TextUtils.equals("1", PreferenceUtils.getPrefString("account_type", ""))) {
                                                if (TextUtils.equals("0", been.getResponse())) {
                                                    future_all_count.setVisibility(View.INVISIBLE);
                                                } else {
                                                    future_all_count.setVisibility(View.VISIBLE);
                                                    future_all_count.setText(been.getResponse());
                                                }
                                            } else {
                                                if (TextUtils.equals("0", been.getResponse())) {
                                                    serverce_server_count.setVisibility(View.INVISIBLE);
                                                } else {
                                                    serverce_server_count.setVisibility(View.VISIBLE);
                                                    serverce_server_count.setText(been.getResponse());
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });
            }
        }).start();

    }

    private void initNeedManage(final String userId) {
        Map<String, String> map = new HashMap<>();
        map.put("user_id", userId);
        final String sign = GetSign.getSign(map);
        new Thread(new Runnable() {
            @Override
            public void run() {

                OkHttpUtils
                        .get()
                        .url(Constant.GETUER_DEMAND_COUNT)
                        .addParams("user_id", userId)
                        .addParams("sign", sign)
                        .build()
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Call call, Exception e, int id) {
                                ToastUtils.showToast("网络请求异常");
                            }

                            @Override
                            public void onResponse(String response, int id) {
                                Gson gson = new Gson();
                                final HaveNeerReedBeen been = gson.fromJson(response, HaveNeerReedBeen.class);
                                if (been == null) {
                                    ToastUtils.showToast("网络请求异常");
                                    return;
                                }
                                if (!TextUtils.equals("0", been.getErrCode())) {
                                    ToastUtils.showToast(been.getErrMsg());
                                    return;
                                }
                                if (TextUtils.equals("0", been.getErrCode())) {

                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {

                                            if (TextUtils.equals("1", PreferenceUtils.getPrefString("account_type", ""))) {
                                                if (TextUtils.equals("0", been.getResponse())) {
                                                    need_all_count.setVisibility(View.INVISIBLE);
                                                } else {
                                                    need_all_count.setVisibility(View.VISIBLE);
                                                    need_all_count.setText(been.getResponse());
                                                }
                                            } else {

                                                if (TextUtils.equals("0", been.getResponse())) {
                                                    servecr_all_count.setVisibility(View.INVISIBLE);
                                                } else {
                                                    servecr_all_count.setVisibility(View.VISIBLE);
                                                    servecr_all_count.setText(been.getResponse());
                                                }
                                            }
                                        }
                                    });
                                }
                            }
                        });

            }
        }).start();


    }

    private void initNeed(final String userId) {
        Map<String, String> map = new HashMap<>();
        map.put("user_id", userId);
        final String sign = GetSign.getSign(map);
        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpUtils
                        .get()
                        .url(Constant.GETUER_SHOW_MESSAGE)
                        .addParams("user_id", userId)
                        .addParams("sign", sign)
                        .build()
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Call call, Exception e, int id) {
                                ToastUtils.showToast("网络请求异常");
                            }

                            @Override
                            public void onResponse(String response, int id) {
                                Gson gson = new Gson();
                                final HaveNeerReedBeen been = gson.fromJson(response, HaveNeerReedBeen.class);
                                if (been == null) {
                                    ToastUtils.showToast("网络请求异常");
                                    return;
                                }
                                if (!TextUtils.equals("0", been.getErrCode())) {
                                    ToastUtils.showToast(been.getErrMsg());
                                    return;
                                }
                                if (TextUtils.equals("0", been.getErrCode())) {
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            if (TextUtils.equals("0", been.getResponse())) {
                                                all_count.setVisibility(View.INVISIBLE);
                                            } else {
                                                all_count.setVisibility(View.VISIBLE);
                                                all_count.setText(been.getResponse());
                                            }
                                        }
                                    });
                                }
                            }
                        });
            }
        }).start();
    }

    private String getAppInfo() {
        try {
            String pkName = ExitApplication.context.getPackageName();
            String versionName = ExitApplication.context.getPackageManager().getPackageInfo(
                    pkName, 0).versionName;
            return versionName;
        } catch (Exception e) {
            return "未知版本号";
        }

    }


    private void getOrderNum(String userId) {
        String sign = ApiRequest.getSign("user_id", userId);
        ApiRequest.getOrderCount(userId, sign, new MyCallBack<OrderNumObj>(getActivity(), true) {
            @Override
            public void onSuccessful(OrderNumObj response) {
                if (response.getErrCode() == 0) {
                    OrderNumObj.ResponseBean bean = response.getResponse();
                    if (bean.getPending_payment_count() > 0) {
                        tv_dfk.setVisibility(View.VISIBLE);
                        tv_dfk.setText(bean.getPending_payment_count() + "");
                    } else {
                        tv_dfk.setVisibility(View.INVISIBLE);
                    }
                    if (bean.getTobe_shipped_count() > 0) {
                        tv_dfh.setVisibility(View.VISIBLE);
                        tv_dfh.setText(bean.getTobe_shipped_count() + "");
                    } else {
                        tv_dfh.setVisibility(View.INVISIBLE);
                    }
                    if (bean.getReceipt_goods_count() > 0) {
                        tv_dsh.setVisibility(View.VISIBLE);
                        tv_dsh.setText(bean.getReceipt_goods_count() + "");
                    } else {
                        tv_dsh.setVisibility(View.INVISIBLE);
                    }
                    if (bean.getTobe_evaluated_count() > 0) {
                        tv_dpj.setVisibility(View.VISIBLE);
                        tv_dpj.setText(bean.getTobe_evaluated_count() + "");
                    } else {
                        tv_dpj.setVisibility(View.INVISIBLE);
                    }
                    if (bean.getAfter_sales_count() > 0) {
                        tv_thh.setVisibility(View.VISIBLE);
                        tv_thh.setText(bean.getAfter_sales_count() + "");
                    } else {
                        tv_thh.setVisibility(View.INVISIBLE);
                    }

                } else {
                    tv_dfk.setVisibility(View.INVISIBLE);
                    tv_dfh.setVisibility(View.INVISIBLE);
                    tv_dsh.setVisibility(View.INVISIBLE);
                    tv_dpj.setVisibility(View.INVISIBLE);
                    tv_thh.setVisibility(View.INVISIBLE);
                }

            }
        });
    }

    private void setViewForUser() {
        String userType = PreferenceUtils.getUserType("account_type");
        switch (userType) {
            case "1":
                tv_usertype.setText("需求商");
                ll_center_mall.setVisibility(View.VISIBLE);

                ll_menu_xuqiushang.setVisibility(View.VISIBLE);
                fl_xuqiushang.setVisibility(View.VISIBLE);

                ll_menu_fuwushang.setVisibility(View.GONE);
                ll_fuwushang.setVisibility(View.GONE);
                break;
            case "2":

                tv_usertype.setText("服务商");
                ll_center_mall.setVisibility(View.GONE);


                fl_xuqiushang.setVisibility(View.GONE);
                ll_menu_xuqiushang.setVisibility(View.GONE);

                ll_menu_fuwushang.setVisibility(View.VISIBLE);
                ll_fuwushang.setVisibility(View.VISIBLE);


                servecr_all_count.setVisibility(View.VISIBLE);
                serverce_server_count.setVisibility(View.VISIBLE);

            case "3":
                tv_usertype.setText("服务商");
                ll_center_mall.setVisibility(View.GONE);


                fl_xuqiushang.setVisibility(View.GONE);
                ll_menu_xuqiushang.setVisibility(View.GONE);

                ll_menu_fuwushang.setVisibility(View.VISIBLE);
                ll_fuwushang.setVisibility(View.VISIBLE);

                servecr_all_count.setVisibility(View.VISIBLE);
                serverce_server_count.setVisibility(View.VISIBLE);

                break;
            default:
                tv_usertype.setText("需求商");
                ll_center_mall.setVisibility(View.VISIBLE);

                ll_menu_xuqiushang.setVisibility(View.VISIBLE);
                fl_xuqiushang.setVisibility(View.VISIBLE);

                ll_menu_fuwushang.setVisibility(View.GONE);
                ll_fuwushang.setVisibility(View.GONE);
                ll_menu_fuwushang.setVisibility(View.GONE);
                ll_fuwushang.setVisibility(View.GONE);


                break;
        }
    }

    private void httpGetUserInfo(final String userId) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", userId));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", userId);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getContext(), false, Constant.GetUser_model, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            if (Errmsg.equals("未找到用户")) {
                                PreferenceUtils.setPrefString("user_id", "");
                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            }
                            return;
                        case 0:// 成功
                            UserInfoModel user_info = gson.fromJson(Response, UserInfoModel.class);
                            UserInfoModel.setUser_info(user_info);

                            ImageLoader.getInstance().displayImage(user_info.getHead_portrait(), center_img);
                            center_name.setText(user_info.getNet_name());
                            coupons_count.setText(user_info.getCoupons_count() + "张");
                            integral.setText(user_info.getIntegral() + "积分");
                            String userType = PreferenceUtils.getUserType("account_type");
                            if (!"1".equals(userType)) {//1需求商 2服务商
                                service_balance.setText("¥" + user_info.getBalance() + "元");
                            }
                            httpGetpd_userlogin(userId);
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    private void httpGetpd_userlogin(String userId) {// 获取手机唯一标识
        TelephonyManager TelephonyMgr = (TelephonyManager) ExitApplication.context.getSystemService(Activity.TELEPHONY_SERVICE);
        String equipment = TelephonyMgr.getDeviceId();
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", userId));
        list.add(new NameValuePairSign("equipment", equipment));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", userId);
        params.addQueryStringParameter("equipment", equipment);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(getActivity(), false, Constant.Getpd_userlogin, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            if (Errmsg.equals("未找到用户")) {
                                PreferenceUtils.setPrefString("user_id", "");
                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            }
                            return;
                        case 0:// 成功
                            JSONObject js = new JSONObject(Response);
                            if (!"2".equals(js.getString("status"))) {
                                //                                PreferenceUtils.setPrefString("user_id", "");
                                //                                PreferenceUtils.setPrefString("account_type", "");
                                Intent intent = new Intent(getActivity(), LoginActivity.class);
                                intent.putExtra("tag", "2");
                                startActivity(intent);
                            }
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }

    @OnClick({R.id.center_message, R.id.center_img, R.id.center_coupon, R.id.center_point,
            R.id.center_xiuqiu_gl, R.id.center_yuyue_gl, R.id.center_address_gl, R.id.center_money,
            R.id.center_collect, R.id.center_eva, R.id.center_qiuzhi, R.id.center_group_gl,
            R.id.order_dfk, R.id.order_dfh, R.id.order_dsh, R.id.order_eva, R.id.order_thh,
            R.id.service_xiuqiu_dd, R.id.service_fuwu_dd, R.id.service_eva, R.id.service_zhaopin,
            R.id.service_money, R.id.center_group_gl_fuwu,R.id.service_chenge
    })
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            //服务商
            case R.id.service_xiuqiu_dd://需求订单
                intent.setClass(getActivity(), ServiceXuqiuActivity.class);
                startActivity(intent);
                break;
            case R.id.service_fuwu_dd://TODO:进入服务订单
                intent.setClass(getActivity(), ServiceFuwuActivity.class);
                startActivity(intent);
                break;
            case R.id.service_eva://我的评价
                intent.setClass(getActivity(), ServiceEvaluateActivity.class);
                startActivity(intent);
                break;
            case R.id.service_zhaopin://我的招聘
                intent.setClass(getActivity(), ServiceRecruitActivity.class);
                startActivity(intent);
                break;
            case R.id.service_money://我的钱包
                intent.setClass(getActivity(), MyMoneyActivity.class);
                startActivity(intent);
                break;
            case R.id.center_group_gl_fuwu://论坛管理
                intent.setClass(getActivity(), MyForumActivity.class);
                startActivity(intent);
                break;
            case R.id.center_message:// 消息
                intent.setClass(getActivity(), MyMessageActivity.class);
                startActivity(intent);
                break;
            case R.id.center_img:// 头像
                if (TextUtils.isEmpty(PreferenceUtils.getPrefString("account_type", "")) || TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                    intent.setClass(getActivity(), LoginActivity.class);
                    startActivity(intent);

                } else {

                    if (TextUtils.equals(PreferenceUtils.getPrefString("account_type", ""), "1") || TextUtils.isEmpty(PreferenceUtils.getPrefString("account_type", ""))) {
                        intent.setClass(getActivity(), CenterInfoActivity.class);
                        startActivity(intent);
                    } else {
                        intent.setClass(getActivity(), ServiceInfoActivity.class);
                        startActivity(intent);
                    }
                }
                break;
            case R.id.center_coupon:// 我的优惠券
                intent.setClass(getActivity(), MyCouponActivity.class);
                startActivity(intent);
                break;
            case R.id.center_point:// 我的积分
                intent.setClass(getActivity(), MyPointActivity.class);
                startActivity(intent);
                break;
            case R.id.center_xiuqiu_gl:// 需求管理
                intent.setClass(getActivity(), MyXuqiuActivity.class);
                startActivity(intent);
                break;
            case R.id.center_yuyue_gl:// 预约管理
                intent.setClass(getActivity(), MyYuyueActivity.class);
                startActivity(intent);
                break;
            case R.id.center_address_gl:// 地址管理
                intent.setClass(getActivity(), QMyAddressActivity.class);
                //                intent.setClass(getActivity(), MyAddressActivity.class);
                startActivity(intent);
                break;
            case R.id.center_money:// 我的钱包
                intent.setClass(getActivity(), MyMoneyActivity.class);
                startActivity(intent);
                break;
            case R.id.center_collect:// 我的收藏
                intent.setClass(getActivity(), MyCollectActivity.class);
                startActivity(intent);
                break;
            case R.id.center_eva:// 我的评价
                intent.setClass(getActivity(), MyEvaluateActivity.class);
                startActivity(intent);
                break;
            case R.id.center_qiuzhi:// 我的求职
                intent.setClass(getActivity(), MyJobActivity.class);
                startActivity(intent);
                break;
            case R.id.center_group_gl:// 论坛管理
                intent.setClass(getActivity(), MyForumActivity.class);
                startActivity(intent);
                break;
            case R.id.order_dfk:// 待付款
                intent.setClass(getActivity(), MyOrderActivity.class);
                intent.putExtra("order_type", "nopay");
                startActivity(intent);
                break;
            case R.id.order_dfh:// 待发货
                intent.setClass(getActivity(), MyOrderActivity.class);
                intent.putExtra("order_type", "already_send");
                startActivity(intent);
                break;
            case R.id.order_dsh:// 待收货
                intent.setClass(getActivity(), MyOrderActivity.class);
                intent.putExtra("order_type", "already_get");
                startActivity(intent);
                break;
            case R.id.order_eva:// 待评价
                intent.setClass(getActivity(), MyOrderActivity.class);
                intent.putExtra("order_type", "already_eva");
                startActivity(intent);
                break;
            case R.id.order_thh:// 退换货
                intent.setClass(getActivity(), MyReturnActivity.class);
                startActivity(intent);
                break;
            case R.id.service_chenge:
                intent.setClass(getActivity(), ServiceFuwuActivity.class);
                intent.putExtra("formesever", "formesever");
                startActivity(intent);
                break;
        }
    }

    //主要用于检测内存泄漏
    @Override
    public void onDestroy() {
        super.onDestroy();
        RefWatcher refWatcher = ExitApplication.getRefWatcher(getActivity());
        refWatcher.watch(this);
    }
}
